package com.zjdiepu.www.biz.his;

import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.core.BaseService;
import com.zjdiepu.www.base.enums.status.AuditListStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.LoanEditStatus;
import com.zjdiepu.www.base.enums.type.BusinessExtrasCodeType;
import com.zjdiepu.www.base.enums.type.BusinessExtrasType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.dao.dh.DhRemindLoanMapper;
import com.zjdiepu.www.dao.dh.FkInsureListMapper;
import com.zjdiepu.www.dao.dz.DzGpsListMapper;
import com.zjdiepu.www.dao.dz.DzPickCarMapper;
import com.zjdiepu.www.dao.fk.FkAuditListMapper;
import com.zjdiepu.www.dao.his.HisYwBusinessLoanMapper;
import com.zjdiepu.www.dao.other.OtherAuditInfoMapper;
import com.zjdiepu.www.dao.other.OtherBusiSalersChangeMapper;
import com.zjdiepu.www.dao.yw.YwBusinessCarMapper;
import com.zjdiepu.www.dao.yw.YwBusinessExtrasMapper;
import com.zjdiepu.www.dao.yw.YwBusinessLoanEditMapper;
import com.zjdiepu.www.dao.yw.YwBusinessLoanMapper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.dao.yw.YwFeesMapper;
import com.zjdiepu.www.dao.yw.YwFeesSubMapper;
import com.zjdiepu.www.dao.yw.YwTransferMapper;
import com.zjdiepu.www.ibiz.his.IHisYwBusinessLoanService;
import com.zjdiepu.www.ibiz.zpp.SystemService;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.dh.dto.DhRemindLoan;
import com.zjdiepu.www.model.dh.dto.FkInsureList;
import com.zjdiepu.www.model.dh.ext.DhRemindLoanExt;
import com.zjdiepu.www.model.dh.ext.FkInsureListExt;
import com.zjdiepu.www.model.dz.dto.DzGpsList;
import com.zjdiepu.www.model.dz.dto.DzPickCar;
import com.zjdiepu.www.model.dz.ext.DzGpsListExt;
import com.zjdiepu.www.model.fk.dto.FkAuditList;
import com.zjdiepu.www.model.fk.ext.FkAuditListExt;
import com.zjdiepu.www.model.his.dto.HisYwBusinessLoan;
import com.zjdiepu.www.model.his.ext.HisYwBusinessLoanExt;
import com.zjdiepu.www.model.other.dto.OtherAuditInfo;
import com.zjdiepu.www.model.other.dto.OtherBusiSalersChange;
import com.zjdiepu.www.model.other.ext.OtherBusiSalersChangeExt;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessExtras;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoanEdit;
import com.zjdiepu.www.model.yw.dto.YwFees;
import com.zjdiepu.www.model.yw.dto.YwFeesSub;
import com.zjdiepu.www.model.yw.dto.YwTransfer;
import com.zjdiepu.www.util.ExceptionHelper;

/**
 * his_贷款信息历史记录Service层操作实现<br/>
 * @author xiongxiaotun<br/>
 * @time 2017年10月18日 11时56分<br/>
 * @since 1.0<br/>
 */
@Service
public class HisYwBusinessLoanServiceImpl extends BaseService implements IHisYwBusinessLoanService {
	public static final Logger logger = LoggerFactory.getLogger(HisYwBusinessLoanServiceImpl.class);

	@Autowired
	private HisYwBusinessLoanMapper hisYwBusinessLoanMapper;
	@Autowired
	private YwFeesMapper ywFeesMapper;
	@Autowired
	private FkAuditListMapper fkAuditListMapper;
	@Autowired
	private FkInsureListMapper fkInsureListMapper;
	@Autowired
	private YwBusinessCarMapper ywBusinessCarMapper;
	@Autowired
	private DhRemindLoanMapper dhRemindLoanMapper;
	@Autowired
	private DzGpsListMapper dzGpsListMapper;
	@Autowired
	private OtherBusiSalersChangeMapper otherBusiSalersChangeMapper;
	@Autowired
	private YwBusinessMapper ywBusinessMapper;
	@Autowired
	private YwBusinessLoanEditMapper ywBusinessLoanEditMapper;
	@Autowired
	private YwBusinessLoanMapper ywBusinessLoanMapper;
	@Autowired
	private YwBusinessExtrasMapper ywBusinessExtrasMapper;
	@Autowired
	private DzPickCarMapper dzPickCarMapper;
	@Autowired
	private YwTransferMapper ywTransferMapper;
	@Autowired
	private YwFeesSubMapper ywFeesSubMapper;
	@Autowired
	private OtherAuditInfoMapper otherAuditInfoMapper;
	@Autowired
	private SystemService systemService;
	
	/**
	 * 更新贷款额
	 * @param busiId
	 * @param loanAmount
	 */
	private void updateLoan(String busiId, Double loanAmount, Double signLoanAmount, Double carPrice, 
			Double rebateDealer, Double rebateProvince, Double rebateArea, String rebateType, Double servicePrice) {
//		更新yw_business,yw_按揭日报表、fk_待审批列表、dh_待投保列表、dh_放款还款提醒、dz_gps待加装列表、other_订单业务员变更的贷款额
		YwBusiness ywBusiness = new YwBusiness();
		ywBusiness.setId(busiId);
		ywBusiness.setSignLoanAmount(signLoanAmount);
		ywBusiness.setRealLoanAmount(loanAmount);
		ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		
		YwFees ywFees = new YwFees();
		ywFees.setDpStatus(DpStatus.NORMAL.getCode());
		ywFees.setBusiId(busiId);
		ywFees = ywFeesMapper.selectRefined(ywFees);
		if(null != ywFees) {
			ywFees.setAmount(loanAmount);
			ywFees.setSignLoanAmount(signLoanAmount);
			
			ywFees.setRebateDealer(rebateDealer);
			ywFees.setRebateProvince(rebateProvince);
			ywFees.setRebateArea(rebateArea);
			ywFees.setRebateType(rebateType);
			ywFeesMapper.updateByPrimaryKeySelective(ywFees);
		}
		
		YwFeesSub ywFeesSub = new YwFeesSub();
		ywFeesSub.setDpStatus(DpStatus.NORMAL.getCode());
		ywFeesSub.setBusiId(busiId);
		ywFeesSub.setItemCode("01");
		ywFeesSub = ywFeesSubMapper.selectRefined(ywFeesSub);
		if(ywFeesSub != null) {
			ywFeesSub.setAmountItem(servicePrice);
			ywFeesSubMapper.updateByPrimaryKeySelective(ywFeesSub);
		}
		
		FkAuditListExt fkAuditListExt = new FkAuditListExt();
		fkAuditListExt.setBaseWhere();
		fkAuditListExt.setAuditListStatus(AuditListStatus.WEI_SHEN_PI.getCode());
		fkAuditListExt.setBusiId(busiId);
		List<FkAuditList> fkAuditLists = fkAuditListMapper.selectByExt(fkAuditListExt);
		for(FkAuditList fkAuditList : fkAuditLists) {
			fkAuditList.setLoanAmount(loanAmount);
			fkAuditListMapper.updateByPrimaryKeySelective(fkAuditList);
		}
		
		FkInsureListExt fkInsureListExt = new FkInsureListExt();
		fkInsureListExt.setBaseWhere();
		fkInsureListExt.setBusiId(busiId);
		List<FkInsureList> fkInsureLists = fkInsureListMapper.selectByExt(fkInsureListExt);
		for(FkInsureList fkInsureList : fkInsureLists) {
			fkInsureList.setLoanAmount(loanAmount);
			fkInsureListMapper.updateByPrimaryKeySelective(fkInsureList);
		}
		
		DhRemindLoanExt dhRemindLoanExt = new DhRemindLoanExt(); 
		dhRemindLoanExt.setBaseWhere();
		dhRemindLoanExt.setBusiId(busiId);
		List<DhRemindLoan> dhRemindLoans = dhRemindLoanMapper.selectByExt(dhRemindLoanExt);
		for(DhRemindLoan dhRemindLoan : dhRemindLoans) {
			dhRemindLoan.setLoanAmount(loanAmount);
			dhRemindLoanMapper.updateByPrimaryKeySelective(dhRemindLoan);
		}
		
		DzGpsListExt dzGpsListExt = new DzGpsListExt();
		dzGpsListExt.setBaseWhere();
		dzGpsListExt.setBusiId(busiId);
		List<DzGpsList> dzGpsLists = dzGpsListMapper.selectByExt(dzGpsListExt);
		for(DzGpsList dzGpsList : dzGpsLists) {
			dzGpsList.setLoanAmount(loanAmount);
			dzGpsListMapper.updateByPrimaryKeySelective(dzGpsList);
		}
		
		OtherBusiSalersChangeExt otherBusiSalersChangeExt = new OtherBusiSalersChangeExt();
		otherBusiSalersChangeExt.setBaseWhere();
		otherBusiSalersChangeExt.setBusiId(busiId);
		List<OtherBusiSalersChange> otherBusiSalersChanges = otherBusiSalersChangeMapper.selectByExt(otherBusiSalersChangeExt);
		for(OtherBusiSalersChange otherBusiSalersChange : otherBusiSalersChanges) {
			otherBusiSalersChange.setLoanAmount(loanAmount);
			otherBusiSalersChangeMapper.updateByPrimaryKeySelective(otherBusiSalersChange);
		}
		
		YwBusinessCar ywBusinessCar = new YwBusinessCar();
		ywBusinessCar.setDpStatus(DpStatus.NORMAL.getCode());
		ywBusinessCar.setBusiId(busiId);
		ywBusinessCar = ywBusinessCarMapper.selectRefined(ywBusinessCar);
		if(null != ywBusinessCar){
			ywBusinessCar.setPrice(carPrice);
			ywBusinessCarMapper.updateByPrimaryKeySelective(ywBusinessCar);
		}
		
		DzPickCar dzPickCar = new DzPickCar();
		dzPickCar.setDpStatus(DpStatus.NORMAL.getCode());
		dzPickCar.setBusiId(busiId);
		dzPickCar = dzPickCarMapper.selectRefined(dzPickCar);
		if(null != dzPickCar){
			dzPickCar.setPrice(carPrice);
			dzPickCarMapper.updateByPrimaryKeySelective(dzPickCar);
		}
		YwTransfer ywTransfer = new YwTransfer();
		ywTransfer.setDpStatus(DpStatus.NORMAL.getCode());
		ywTransfer.setBusiId(busiId);
		ywTransfer = ywTransferMapper.selectRefined(ywTransfer);
		if(null != ywTransfer){
			ywTransfer.setPrice(carPrice);
			ywTransferMapper.updateByPrimaryKeySelective(ywTransfer);
		}
		
		
	}
	
	@Override
	public void saveAudit(String busiId, boolean pass, AbstractSysUser currentUser) {
		YwBusiness ywBusiness = ywBusinessMapper.selectByPrimaryKey(busiId);
		if(ywBusiness == null) {
			ExceptionHelper.thow(ResultFlagType.MISSING);
		}
		//新数据
		YwBusinessLoanEdit ywBusinessLoanEdit = new YwBusinessLoanEdit();
		ywBusinessLoanEdit.setDpStatus(DpStatus.NORMAL.getCode());
		ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.YI_SHEN_QING.getCode());
		ywBusinessLoanEdit.setBusiId(busiId);
		ywBusinessLoanEdit = ywBusinessLoanEditMapper.selectRefined(ywBusinessLoanEdit);
		if(ywBusinessLoanEdit == null) {
			ExceptionHelper.thow(ResultFlagType.MISSING);
		}
		if(pass) {
//		资金流程状态
			Integer addedStatus1 = ywBusiness.getAddedStatus1();
			if(addedStatus1 != null && addedStatus1 > 100) {
				ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_2_SHEN_HE_ZHONG.getCode());
				//审核通过时，如果不需要审核二，那么给业务员推送app信息；如果需要审核二，那么给特定人员（数据字典 Edit_Loan_SHOne_Inform）发送站内信。
				//参数一：1：通过，0：拒绝；参数二：1：需要发送给特定人，0：不需要发送给特定人
				systemService.diepuNewsHandle(currentUser, ModeIDType.XGDKSHY.getCode(), "35", busiId, null, "1", "1");
			} else {
				ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_1_TONG_GUO.getCode());
				
				YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
				ywBusinessLoan.setBusiId(busiId);
				ywBusinessLoan.setDpStatus(DpStatus.NORMAL.getCode());
				int countRefined = ywBusinessLoanMapper.countRefined(ywBusinessLoan);
				if(countRefined == 0) {
					ExceptionHelper.thow("999","贷款记录丢失,请联系管理员处理!");
				} else if(countRefined > 1) {
					ExceptionHelper.thow("999","贷款记录存在多条,请联系管理员处理!");
				}
				String loanId = ywBusinessLoanEdit.getLoanId();
				YwBusinessLoan ywBusinessLoanDb = ywBusinessLoanMapper.selectByPrimaryKey(loanId);
				if(null == ywBusinessLoanDb) {
					ExceptionHelper.thow("999","贷款记录丢失,请联系管理员处理!");
				}
				
				BeanUtils.copyProperties(ywBusinessLoanEdit, ywBusinessLoan);
				ywBusinessLoan.setId(loanId);
				ywBusinessLoanMapper.updateByPrimaryKeySelective(ywBusinessLoan);
				
				updateLoan(busiId, ywBusinessLoanEdit.getLoanAmount(), ywBusinessLoanEdit.getSignLoanAmount(), ywBusinessLoanEdit.getCarPrice(),
						ywBusinessLoanEdit.getRebateDealer(), ywBusinessLoanEdit.getRebateProvince(), ywBusinessLoanEdit.getRebateArea(), ywBusinessLoanEdit.getRebateType(), ywBusinessLoanEdit.getServicePrice());
				//参数一：1：通过，0：拒绝；参数二：1：需要发送给特定人，0：不需要发送给特定人
				systemService.diepuNewsHandle(currentUser, ModeIDType.XGDKSHY.getCode(), "35", busiId, null, "1","0");
			}
			
			SysUser sysUser = (SysUser)currentUser;
			OtherAuditInfo otherAuditInfo = new OtherAuditInfo();
			otherAuditInfo.initInsertData(sysUser.getId(), sysUser.getName());
			otherAuditInfo.setModeId(ModeIDType.XGDKSHY.getCode());
			otherAuditInfo.setBusiId(busiId);
			otherAuditInfo.setDataId(ywBusinessLoanEdit.getId());
			otherAuditInfo.setAuditName(ModeIDType.XGDKSHY.getValue());
			otherAuditInfo.setOrgCode(sysUser.getOrgId());
			otherAuditInfo.setOrgName(sysUser.getOrgName());
			otherAuditInfo.setAuditStatus(AuditListStatus.SHEN_PI_TONG_GUO.getCode().toString());
			otherAuditInfoMapper.insert(otherAuditInfo);
			
			ywBusinessLoanEditMapper.updateByPrimaryKeySelective(ywBusinessLoanEdit);
		} else {
			
			SysUser sysUser = (SysUser)currentUser;
			OtherAuditInfo otherAuditInfo = new OtherAuditInfo();
			otherAuditInfo.initInsertData(sysUser.getId(), sysUser.getName());
			otherAuditInfo.setModeId(ModeIDType.XGDKSHY.getCode());
			otherAuditInfo.setBusiId(busiId);
			otherAuditInfo.setDataId(ywBusinessLoanEdit.getId());
			otherAuditInfo.setAuditName(ModeIDType.XGDKSHY.getValue());
			otherAuditInfo.setOrgCode(sysUser.getOrgId());
			otherAuditInfo.setOrgName(sysUser.getOrgName());
			otherAuditInfo.setAuditStatus(AuditListStatus.SHEN_PI_BU_TONG_GUO.getCode().toString());
			otherAuditInfoMapper.insert(otherAuditInfo);
			
			ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_1_BU_TONG_GUO.getCode());
			ywBusinessLoanEditMapper.updateByPrimaryKeySelective(ywBusinessLoanEdit);
			
			//如果拒绝，那么给业务员推送app。
			//参数一：1：通过，0：拒绝；参数二：1：需要发送给特定人，0：不需要发送给特定人
			systemService.diepuNewsHandle(currentUser, ModeIDType.XGDKSHY.getCode(), "35", busiId, null, "0", "0");
		}
		
		YwBusinessExtras ywBusinessExtrasParam = new YwBusinessExtras();
		ywBusinessExtrasParam.setBusiId(busiId);
		ywBusinessExtrasParam.setDpStatus(DpStatus.NORMAL.getCode());
		ywBusinessExtrasParam.setTypeExtras(BusinessExtrasType.LOCK_STATUS.getCode());
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.LOAN_EDIT_LOCK.getCode());
		YwBusinessExtras ywBusinessExtras = ywBusinessExtrasMapper.selectRefined(ywBusinessExtrasParam);
		if(null == ywBusinessExtras) {
			ywBusinessExtras = ywBusinessExtrasParam;
			ywBusinessExtrasParam.initInsertData(currentUser.getId(), currentUser.getName());
			ywBusinessExtras.setValueExtras("2");
			ywBusinessExtrasMapper.insert(ywBusinessExtras);
		} else {
			ywBusinessExtras.setValueExtras("2");
			ywBusinessExtrasMapper.updateByPrimaryKey(ywBusinessExtras);
		}
	}
	
	@Override
	public void saveAuditB(String busiId, boolean pass,
			AbstractSysUser currentUser) {
		//新数据
		YwBusinessLoanEdit ywBusinessLoanEdit = new YwBusinessLoanEdit();
		ywBusinessLoanEdit.setDpStatus(DpStatus.NORMAL.getCode());
		ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_2_SHEN_HE_ZHONG.getCode());
		ywBusinessLoanEdit.setBusiId(busiId);
		ywBusinessLoanEdit = ywBusinessLoanEditMapper.selectRefined(ywBusinessLoanEdit);
		if(ywBusinessLoanEdit == null) {
			ExceptionHelper.thow(ResultFlagType.MISSING);
		}

		if (pass) {
			ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_2_TONG_GUO.getCode());
			ywBusinessLoanEditMapper.updateByPrimaryKeySelective(ywBusinessLoanEdit);

			YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
			ywBusinessLoan.setBusiId(busiId);
			ywBusinessLoan.setDpStatus(DpStatus.NORMAL.getCode());
			int countRefined = ywBusinessLoanMapper.countRefined(ywBusinessLoan);
			if(countRefined == 0) {
				ExceptionHelper.thow("999","贷款记录丢失,请联系管理员处理!");
			} else if(countRefined > 1) {
				ExceptionHelper.thow("999","贷款记录存在多条,请联系管理员处理!");
			}
			String loanId = ywBusinessLoanEdit.getLoanId();
			YwBusinessLoan ywBusinessLoanDb = ywBusinessLoanMapper.selectByPrimaryKey(loanId);
			if(null == ywBusinessLoanDb) {
				ExceptionHelper.thow("999","贷款记录丢失,请联系管理员处理!");
			}
			
			BeanUtils.copyProperties(ywBusinessLoanEdit, ywBusinessLoan);
			ywBusinessLoan.setId(loanId);
			ywBusinessLoanMapper.updateByPrimaryKeySelective(ywBusinessLoan);
			
			//修改各处贷款额
			updateLoan(busiId, ywBusinessLoanEdit.getLoanAmount(), ywBusinessLoanEdit.getSignLoanAmount(), ywBusinessLoanEdit.getCarPrice(), 
					ywBusinessLoanEdit.getRebateDealer(), ywBusinessLoanEdit.getRebateProvince(), ywBusinessLoanEdit.getRebateArea(), ywBusinessLoanEdit.getRebateType(), ywBusinessLoanEdit.getServicePrice());
		
			SysUser sysUser = (SysUser)currentUser;
			OtherAuditInfo otherAuditInfo = new OtherAuditInfo();
			otherAuditInfo.initInsertData(sysUser.getId(), sysUser.getName());
			otherAuditInfo.setModeId(ModeIDType.XGDKSHE.getCode());
			otherAuditInfo.setBusiId(busiId);
			otherAuditInfo.setDataId(ywBusinessLoanEdit.getId());
			otherAuditInfo.setAuditName(ModeIDType.XGDKSHE.getValue());
			otherAuditInfo.setOrgCode(sysUser.getOrgId());
			otherAuditInfo.setOrgName(sysUser.getOrgName());
			otherAuditInfo.setAuditStatus(AuditListStatus.SHEN_PI_TONG_GUO.getCode().toString());
			otherAuditInfoMapper.insert(otherAuditInfo);
			
		} else {
			SysUser sysUser = (SysUser)currentUser;
			OtherAuditInfo otherAuditInfo = new OtherAuditInfo();
			otherAuditInfo.initInsertData(sysUser.getId(), sysUser.getName());
			otherAuditInfo.setModeId(ModeIDType.XGDKSHE.getCode());
			otherAuditInfo.setBusiId(busiId);
			otherAuditInfo.setDataId(ywBusinessLoanEdit.getId());
			otherAuditInfo.setAuditName(ModeIDType.XGDKSHE.getValue());
			otherAuditInfo.setOrgCode(sysUser.getOrgId());
			otherAuditInfo.setOrgName(sysUser.getOrgName());
			otherAuditInfo.setAuditStatus(AuditListStatus.SHEN_PI_BU_TONG_GUO.getCode().toString());
			otherAuditInfoMapper.insert(otherAuditInfo);
			
			ywBusinessLoanEdit.setLoanEditStatus(LoanEditStatus.SHEN_HE_2_BU_TONG_GUO.getCode());
			ywBusinessLoanEditMapper.updateByPrimaryKeySelective(ywBusinessLoanEdit);
		}

		YwBusinessExtras ywBusinessExtrasParam = new YwBusinessExtras();
		ywBusinessExtrasParam.setBusiId(busiId);
		ywBusinessExtrasParam.setDpStatus(DpStatus.NORMAL.getCode());
		ywBusinessExtrasParam.setTypeExtras(BusinessExtrasType.LOCK_STATUS.getCode());
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.LOAN_EDIT_LOCK.getCode());
		YwBusinessExtras ywBusinessExtras = ywBusinessExtrasMapper.selectRefined(ywBusinessExtrasParam);
		if (null == ywBusinessExtras) {
			ywBusinessExtras = ywBusinessExtrasParam;
			ywBusinessExtrasParam.initInsertData(currentUser.getId(), currentUser.getName());
			ywBusinessExtras.setValueExtras("2");
			ywBusinessExtrasMapper.insert(ywBusinessExtras);
		} else {
			ywBusinessExtras.setValueExtras("2");
			ywBusinessExtrasMapper.updateByPrimaryKey(ywBusinessExtras);
		}
		
//		审核二通过或者拒绝时，给业务员发推送app信息
		systemService.diepuNewsHandle(currentUser, ModeIDType.XGDKSHE.getCode() , "36", busiId, null, pass ? "1" : "0");
		
	}
	@Override
	public void saveUpdateAndDelete(HisYwBusinessLoan hisYwBusinessLoan, OperateType operType) {
		switch (operType) {
		case add:
			hisYwBusinessLoan.initInsertData(hisYwBusinessLoan.getModifier(), hisYwBusinessLoan.getModifierName());
			hisYwBusinessLoanMapper.insert(hisYwBusinessLoan);
			break;
		case edit:
			hisYwBusinessLoan.initUpdateData(hisYwBusinessLoan.getModifier(), hisYwBusinessLoan.getModifierName());
			// 影响的记录数
			int updateCount = hisYwBusinessLoanMapper.updateByPrimaryKeySelective(hisYwBusinessLoan);
			if(updateCount == 0){
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} else if(updateCount > 1){
				throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
			}
			break;
		case delete:
			hisYwBusinessLoan.initDeleteData(hisYwBusinessLoan.getModifier(), hisYwBusinessLoan.getModifierName());
			// 影响的记录数
			int deleteCount = hisYwBusinessLoanMapper.updateByPrimaryKeySelective(hisYwBusinessLoan);
			if(deleteCount == 0){
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} else if(deleteCount > 1){
				throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
			}
			break;
		default:
			break;
		}
	}
	
	@Override
	public List<HisYwBusinessLoan> selectByExt(HisYwBusinessLoanExt hisYwBusinessLoanExt) {
		return hisYwBusinessLoanMapper.selectByExt(hisYwBusinessLoanExt);
	}
	
	@Override
	public int countByExt(HisYwBusinessLoanExt hisYwBusinessLoanExt){
		return hisYwBusinessLoanMapper.countByExt(hisYwBusinessLoanExt);
	}
	
	@Override
	public HisYwBusinessLoan selectById(String id) {
		return hisYwBusinessLoanMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public void clearEmpty(Set<String> fieldNames, String id) {
		if(CollectionUtils.isNotEmpty(fieldNames)){
			hisYwBusinessLoanMapper.clearEmpty(fieldNames, id);
		}
	}
	
	@Override
	public int countRefined(HisYwBusinessLoan hisYwBusinessLoan) {
		return hisYwBusinessLoanMapper.countRefined(hisYwBusinessLoan);
	}

	@Override
	public HisYwBusinessLoan selectRefined(HisYwBusinessLoan hisYwBusinessLoan) {
		return hisYwBusinessLoanMapper.selectRefined(hisYwBusinessLoan);
	}
	
	@Override
	public int deletedRefined(HisYwBusinessLoan hisYwBusinessLoan) {
		return hisYwBusinessLoanMapper.deletedRefined(hisYwBusinessLoan);
	}

	@Override
	public boolean repeat(HisYwBusinessLoan hisYwBusinessLoan) {
		int count = countRefined(hisYwBusinessLoan);
		if(count > 1) {
			return true;
		}
		if(count == 0) {
			return false;
		}
		
		if(StringUtils.isBlank(hisYwBusinessLoan.getId())) {
			return true;
		}
		HisYwBusinessLoan dbItem = selectRefined(hisYwBusinessLoan);
		if(null == dbItem) {
			return false;
		}
		return !hisYwBusinessLoan.getId().equals(dbItem.getId());
	}
	
	@Override
	public int updateBatch(String modifier, String modifierName, Integer dpStatus, List<String> ids) {
		Integer current = (int)(System.currentTimeMillis() / 1000);
		return hisYwBusinessLoanMapper.updateBatch(modifier, modifierName, current, dpStatus, ids);
	}
	
	@Override
	public int insertBatch(List<HisYwBusinessLoan> hisYwBusinessLoans) {
		return hisYwBusinessLoanMapper.insertBatch(hisYwBusinessLoans);
	}
	
}
